package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.model.entity.Patient;
import com.qf.dao.PatientDao;
import com.qf.service.PatientService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * (Patient)表服务实现类
 *
 * @author makejava
 * @since 2024-04-30 09:17:56
 */
@Service("patientService")
public class PatientServiceImpl implements PatientService {
    @Autowired
    private PatientDao patientDao;

    /**
     * 通过ID查询单条数据
     *
     * @param patientId 主键
     * @return 实例对象
     */
    @Override
    public Patient queryById(Long patientId) {
        return this.patientDao.queryById(patientId);
    }

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @Override
    public PageInfo<Patient> queryByPage(Integer pageNum, Integer pageSize, String patientName, String idNum) {
        PageHelper.startPage(pageNum, pageSize);
        List<Patient> list = patientDao.queryAllByLimit(patientName, idNum);
        return new PageInfo<>(list);

    }

    /**
     * 新增数据
     *
     * @param patient 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(Patient patient) {
        int i = patientDao.insert(patient);
        if (i > 0) {
            return true;
        }
        return false;
    }

    /**
     * 修改数据
     *
     * @param patient 实例对象
     * @return 实例对象
     */
    @Override
    public int update(Patient patient) {
        int i = patientDao.update(patient);
        if (i > 0) {
            return 1;
        }
        return -1;
    }

    /**
     * 通过主键删除数据
     *
     * @param patientId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long patientId) {
        return this.patientDao.deleteById(patientId) > 0;
    }

    @Override
    public int delBatch(List<Integer> list) {
        int i = patientDao.delBatch(list);
        if (i > 0) {
            return 1;
        }
        return -1;
    }
}
